package com.nandasoft.njuerp.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.nandasoft.njuerp.common.entity.ResponseEntity;
import com.nandasoft.njuerp.common.pagination.Page;
import com.nandasoft.njuerp.commons.utils.TimeUtil;
import com.nandasoft.njuerp.entity.DemoEntity;
import com.nandasoft.njuerp.service.DemoService;



@Controller
@RequestMapping(value = "/demo")
public class DemoController {
	private static Logger log = Logger.getLogger(DemoController.class);
	
	@Autowired
	private DemoService demoService;
	
	private ResponseEntity responseEntity;
	
	@RequestMapping(value = "/loadDemo", method = { RequestMethod.GET })
	public ModelAndView loadProjectMain(HttpServletRequest request,HttpServletResponse response) throws Exception {
		ModelAndView modelAndView = null;
		try {
			modelAndView = new ModelAndView("demo/index");
		} catch (Exception ex) {
			ex.printStackTrace();
			throw ex;
		}
		return modelAndView;
	}
	
	
	@RequestMapping(value = "/query", method = { RequestMethod.GET }, produces = { "application/json" })
	@ResponseBody
	public ResponseEntity queryList(String ip, String accountName,Page<DemoEntity> page)
	{
		long startTime = System.currentTimeMillis();
		responseEntity = new ResponseEntity();
		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("qlrmc", "张伟");
		List<Map<String, Object>> li = demoService.queryDemo(paramMap);
		log.info(li);
		long endTime = System.currentTimeMillis();
		long qTime = TimeUtil.getSecond(startTime, endTime);
		responseEntity.setSuccess(true);
		responseEntity.setResult(paramMap);
		responseEntity.setqTime(qTime);
		return responseEntity;
	}
	
	
}
